import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import format from '@dfeidao/atom-web/dt/format';
import get from '@dfeidao/atom-web/global/get';

export default async function a009(fd: IFeidaoAiBrowserComponent,e:Event) {
	// todo
	const ret = get("ret");
	const i=e.currentTarget as HTMLElement;
	const datano=i.getAttribute('data-no');
	 if(datano === '0'){
	
		const res = await nodejs<{d3: Array <{work_bill_no: string, job_content: string, cust_name: string, project_name: string, project_no: string, create_time: number, source_type: string, work_order_status: string }>}>('test-web/zj-000003/s006', {
			filter: {
				project_no:ret
			}
		});
		const ren=await res.d3.map((n) => {
			return {...n,create_time:format(n.create_time,2)};
			});
		
		for (let i = 0; i < ren.length; i++) {
			if (ren[i].source_type == "1") {
				ren[i].source_type = "总服务台";
			} else if (ren[i].source_type == "2") {
				ren[i].source_type = "服务台";
	
			} else if (ren[i].source_type == "3") {
				ren[i].source_type = "客户报障";
	
			} else {
				ren[i].source_type = "内部报障";
			}
	
		}
		for (let i = 0; i < ren.length; i++) {
	
			if (ren[i].work_order_status == "1") {
				ren[i].work_order_status = "结单";
			} else if (ren[i].work_order_status == "2") {
				ren[i].work_order_status = "完成";
	
			} else if (ren[i].work_order_status == "3") {
				ren[i].work_order_status = "挂起";
	
			} else if (ren[i].work_order_status == "4") {
				ren[i].work_order_status = "未派单";
			} else {
				ren[i].work_order_status = "进行中";
			}
		}
		const res1 = await nodejs<{ d1: Array<{ equip_depart_no: string, project_no: string, equip_depart_name: string }> }>( "test-web/zj-000003/s002", {
			filter: {
				project_no: ret
			}
		});

		const arr = Array()
		for (let index = 0; index < res.d3.length; index++) {
			for (let i = 0; i < res1.d1.length; i++) {
					if (res.d3[index].project_no == res1.d1[i].project_no) {
					arr[index] = {
						work_bill_no: res.d3[index].work_bill_no, job_content: res.d3[index].job_content, source_type: ren[index].source_type,
						cust_name: res.d3[index].cust_name, project_name: res.d3[index].project_name, work_order_status: ren[index].work_order_status, create_time: ren[index].create_time, equip_depart_name: res1.d1[i].equip_depart_name
					}
	
				}
			}
		}
		render(fd,arr,p001,"p001",'inner');
		i.setAttribute('data-no','1');
		
	}else if(datano ==="1"){
	

		const res = await nodejs<{d4:Array<{work_bill_no: string, job_content: string, cust_name: string, project_name: string, project_no: string, create_time: number, source_type: string, work_order_status: string }>}>('test-web/zj-000003/s006', {
			filter: {
				// data_v: datav,
				// question_bank_type,
				// topic_type,
				// topic
			}
		});
		const req=await res.d4.map((v) => {
			return {...v,create_time:format(v.create_time,2)};
			});
		
		
		for (let i = 0; i < req.length; i++) {
			if (req[i].source_type == "1") {
				req[i].source_type = "总服务台";
			} else if (req[i].source_type == "2") {
				req[i].source_type = "服务台";
	
			} else if (req[i].source_type == "3") {	
				req[i].source_type = "客户报障";
	
			} else {
				req[i].source_type = "内部报障";
			}
	
		}
		for (let i = 0; i < req.length; i++) {
	
			if (req[i].work_order_status == "1") {
				req[i].work_order_status = "结单";
			} else if (req[i].work_order_status == "2") {
				req[i].work_order_status = "完成";
	
			} else if (req[i].work_order_status == "3") {
				req[i].work_order_status = "挂起";
	
			} else if (req[i].work_order_status == "4") {
				req[i].work_order_status = "未派单";
			} else {
				req[i].work_order_status = "进行中";
			}
		}
		const res1 = await nodejs<{ d1: Array<{ equip_depart_no: string, project_no: string, equip_depart_name: string }> }>( "test-web/zj-000003/s002", {
			filter: {
				project_no: ret
			}
		});

		const arr1 = Array()
		for (let index = 0; index < res.d4.length; index++) {
			for (let i = 0; i < res1.d1.length; i++) {
					if (res.d4[index].project_no == res1.d1[i].project_no) {
					arr1[index] = {
						work_bill_no: res.d4[index].work_bill_no, job_content: res.d4[index].job_content, source_type: req[index].source_type,
						cust_name: res.d4[index].cust_name, project_name: res.d4[index].project_name, work_order_status:req[index].work_order_status, create_time: req[index].create_time, equip_depart_name: res1.d1[i].equip_depart_name
					}
	
				}
			}
		}
		render(fd,arr1,p001,"p001",'inner');
		i.setAttribute('data-no','0');


}	
	
}